home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / CFDFront / CFunctions.c < prev    next >
Encoding:
Text File  |  1992-02-21  |  9.5 KB  |  283 lines  |  [TEXT/MPS ]

  1. // --------------------------------------------------------------------------------------------------
  2. //     Draws a boundry section
  3. // --------------------------------------------------------------------------------------------------
  4. pascal void DrawAllPoints (TObject * tItem, void * tinfo)
  5.     {
  6.     PointInfo    *    info;
  7.     TRow        *    item;
  8.     
  9.     item = (TRow *) tItem;
  10.     info    =    (PointInfo *) tinfo;
  11.     
  12.     item->Each(DrawPoint,info);
  13.     }
  14.     
  15. // --------------------------------------------------------------------------------------------------
  16. //     Draws a boundry section
  17. // --------------------------------------------------------------------------------------------------
  18. pascal void DrawPoint (TObject * tItem, void * tinfo)
  19.     {
  20.     PointInfo    *    info;
  21.     TPoint        *    item;
  22.     
  23.     item = (TPoint *) tItem;
  24.     info = (PointInfo *) tinfo;
  25.     
  26.     if (info->gridOnly && item->IsBoundryPt())
  27.         return;
  28.  
  29.     if (item->IsCornor() && (info->boundry == cLeft || info->boundry == cRight))
  30.         return;
  31.     PenMode(srcXor);
  32.     item->Draw();
  33.     return;
  34.     }
  35.  
  36. // --------------------------------------------------------------------------------------------------
  37. //     Draws a boundry section
  38. // --------------------------------------------------------------------------------------------------
  39. pascal void DrawAllLines (TObject * tItem, void * tinfo)
  40.     {
  41.     PointInfo    *    info;
  42.     TRow        *    item;
  43.     
  44.     item = (TRow *) tItem;
  45.     info    =    (PointInfo *) tinfo;
  46.     
  47.     item->Each(DrawLine,info);
  48.     }
  49.     
  50. // --------------------------------------------------------------------------------------------------
  51. //     Draws a boundry section
  52. // --------------------------------------------------------------------------------------------------
  53. pascal void DrawLine (TObject * tItem, void * tinfo)
  54.     {
  55.     PointInfo    *    info;
  56.     TPoint        *    item;
  57.     
  58.     item = (TPoint *) tItem;
  59.     info    =    (PointInfo *) tinfo;
  60.     if (info->gridOnly)
  61.         {
  62.         if (info->above != NULL && (info->boundry != cLeft && info->boundry != cRight) && !item->IsCornor())
  63.             item->DrawGrid(info->above->fTrans);
  64.         if (info->left != NULL && (info->boundry != cTop && info->boundry != cBottom))
  65.             item->DrawGrid(info->left->fTrans);
  66.         if (item->fObsUpLeft != NULL)
  67.             ((TObstacle *) ((TPoint * ) item)->fObsUpLeft)->Draw();
  68.         if (item->fBaffAbove != NULL)
  69.             ((TBaffle *) ((TPoint * ) item)->fBaffAbove)->Draw();
  70.         if (item->fBaffLeft != NULL)
  71.             ((TBaffle *) ((TPoint * ) item)->fBaffLeft)->Draw();
  72.         return;
  73.         }
  74.     
  75.     if (info->above != NULL)
  76.         {
  77.         if (item->IsCornor() && info->lrc != NULL)
  78.             info->lrc->DrawSection(info->above->fTrans);
  79.         else if (item->IsCornor())
  80.             item->DrawSection(info->above->fTrans);
  81.         else if (info->above->IsBoundryPt() && item->IsBoundryPt() && (info->boundry==cLeft||info->boundry==cRight))
  82.             item->DrawSection(info->above->fTrans);
  83.         else
  84.             item->DrawGrid(info->above->fTrans);
  85.         }
  86.     if (info->left != NULL)
  87.         {
  88.         if (item->IsCornor())
  89.             item->DrawSection(info->left->fTrans);
  90.         else if (!info->noGrid && (info->boundry==cTop||info->boundry==cBottom))
  91.             item->DrawSection(info->left->fTrans);
  92.         else if (!info->noGrid && (info->boundry==cLeft||info->boundry==cRight))
  93.             item->DrawGrid(info->left->fTrans);
  94.         else if (info->left->IsBoundryPt() && item->IsBoundryPt() && (info->boundry==cTop||info->boundry==cBottom))
  95.             item->DrawSection(info->left->fTrans);
  96.         else
  97.             item->DrawGrid(info->left->fTrans);
  98.         }
  99.     if (item->fObsUpLeft != NULL)
  100.         ((TObstacle *) ((TPoint * ) item)->fObsUpLeft)->Draw();
  101.     if (item->fBaffAbove != NULL)
  102.         ((TBaffle *) ((TPoint * ) item)->fBaffAbove)->Draw();
  103.     if (item->fBaffLeft != NULL)
  104.         ((TBaffle *) ((TPoint * ) item)->fBaffLeft)->Draw();
  105.     return;
  106.     }
  107.     
  108. //--------------------------------------------------------------------------------------------------------        
  109. //     determine the slope & intercept for the given points.
  110. //    return false if line is vertical
  111. // --------------------------------------------------------------------------------------------------------        
  112. void SlopeIntercept(slopeStruct * tSlope)
  113.     {                                                                                                                // determine the slope for these points
  114.     extended tx, ty;
  115.     
  116.     tSlope->vertical = false;                                                                            // not vertical
  117.     tSlope->horizontal = false;                                                                        // not horizontal
  118.     tSlope->m = 0;
  119.     tSlope->b  = 0;
  120.     tx = (extended) tSlope->second.h - (extended) tSlope->first.h;                    // get Δx
  121.     ty = (extended) tSlope->second.v - (extended) tSlope->first.v;                    // get Δy
  122.     
  123.     if (tx != 0 && ty != 0)
  124.         {                                                                                                            // sloped line
  125.         tSlope->m = ty / tx;                                                                                // calculate slope
  126.         tSlope->b = (extended) tSlope->first.v - (tSlope->m * (extended) tSlope->first.h);    // calculate y intercept
  127.         return;
  128.         }
  129.     if (!tx)                                                                                                        // vertical line
  130.         {
  131.         tSlope->vertical = true;
  132.         tSlope->b = tSlope->first.v;
  133.         }
  134.     else                                                                                                            // horizontal line
  135.         {
  136.         tSlope->horizontal = true;
  137.         tSlope->b = 0;
  138.         }    
  139.     tSlope->m = 0;
  140.     return;
  141.     }
  142.  
  143. //--------------------------------------------------------------------------------------------------------        
  144. //     determine the distance between the given points.
  145. //    return false if line is vertical
  146. // --------------------------------------------------------------------------------------------------------        
  147. extended CalculateDistance(Point first, Point second)                                     // determine the slope for these points
  148.     {
  149.     extended tx, ty;
  150.     extended dist;
  151.     
  152.     tx = (extended) second.h - (extended) first.h;                                            // get Δx
  153.     ty = (extended) second.v - (extended) first.v;                                            // get Δy
  154.     dist = sqrt((tx * tx) + (ty * ty));
  155.     return dist;
  156.     }
  157.     
  158. // --------------------------------------------------------------------------------------------------------        
  159. //     make the pixel pattern
  160. // --------------------------------------------------------------------------------------------------------        
  161. void     InitColorPattern(void)
  162.     {                                                                                                            // initialize the color pix pattern    
  163.     long colorIndex;
  164.     RGBColor patColor;                                                                                // declaration 
  165.     for (int x=0; x< NumSegmentTypes; x++)    {
  166.         colorIndex = Color2Index(&DrawColors[x]);                                        // convert SegmentColor to an Index
  167.         Index2Color(colorIndex, &patColor);                                                    // convert the index to RGBColor
  168.         SegmentPat[x] = NewPixPat();                                                            // create the pattern data structure
  169.         MakeRGBPat(SegmentPat[x], &patColor);                                            // create the pattern
  170.         }
  171.  
  172. // make pixel pattern for the segment point
  173.  
  174.     colorIndex = Color2Index(&SegmentPoint);
  175.     Index2Color(colorIndex, &patColor);                                                        // convert the index to RGBColor
  176.     SegmentPointPat = NewPixPat();                                                            // create the pattern data structure
  177.     MakeRGBPat(SegmentPointPat, &patColor);                                            // create the pattern
  178.  
  179. // make pixel pattern for the segment point
  180.  
  181.     colorIndex = Color2Index(&StartPoint);
  182.     Index2Color(colorIndex, &patColor);                                                        // convert the index to RGBColor
  183.     StartPointPat = NewPixPat();                                                                // create the pattern data structure
  184.     MakeRGBPat(StartPointPat, &patColor);                                                // create the pattern
  185.  
  186. //    make pixel pattern for the frame
  187.     colorIndex = Color2Index(&BlackColor);
  188.     Index2Color(colorIndex, &patColor);
  189.     PointFramePat = NewPixPat();
  190.     MakeRGBPat(PointFramePat, &patColor);
  191.     
  192. //    make pixel pattern for the frame
  193.     colorIndex = Color2Index(&GridPoint);
  194.     Index2Color(colorIndex, &patColor);
  195.     GridPointPat = NewPixPat();
  196.     MakeRGBPat(GridPointPat, &patColor);
  197.     
  198. //    make pixel pattern for the frame
  199.     colorIndex = Color2Index(&GridLineColor);
  200.     Index2Color(colorIndex, &patColor);
  201.     GridLinePat = NewPixPat();
  202.     MakeRGBPat(GridLinePat, &patColor);
  203.     
  204. //    make pixel pattern for the frame
  205.     colorIndex = Color2Index(&FineGridColor);
  206.     Index2Color(colorIndex, &patColor);
  207.     FineGridPat = NewPixPat();
  208.     MakeRGBPat(FineGridPat, &patColor);
  209.     
  210. //    make pixel pattern for the obstacle
  211.     colorIndex = Color2Index(&ObstacleColor);
  212.     Index2Color(colorIndex, &patColor);
  213.     ObstaclePat = NewPixPat();
  214.     MakeRGBPat(ObstaclePat, &patColor);
  215.     
  216. //    make pixel pattern for the obstacle
  217.     colorIndex = Color2Index(&BaffleColor);
  218.     Index2Color(colorIndex, &patColor);
  219.     BafflePat = NewPixPat();
  220.     MakeRGBPat(BafflePat, &patColor);
  221.     
  222.     return;
  223.     }
  224.  
  225. // --------------------------------------------------------------------------------------------------------        
  226. //     Transform the point for magnification
  227. // --------------------------------------------------------------------------------------------------------        
  228. Point transform(Point t, float mag)
  229.     {
  230.     Point newP;
  231.     
  232.     if (mag == 0)
  233.         return t;
  234.         
  235.     newP.h    = (short) (t.h * mag);
  236.     newP.v    = (short) (t.v * mag);
  237.     return newP;
  238.     }
  239.     
  240. // --------------------------------------------------------------------------------------------------------        
  241. //     Transform the point back
  242. // --------------------------------------------------------------------------------------------------------        
  243. Point AntiTransform(Point t, float mag)
  244.     {
  245.     Point newP;
  246.     
  247.     if (mag == 0)
  248.         return t;
  249.         
  250.     newP.h    = (short) (t.h / mag);
  251.     newP.v    = (short) (t.v / mag);
  252.     return newP;
  253.     }
  254.     
  255. // --------------------------------------------------------------------------------------------------
  256. //     Draws a boundry section
  257. // --------------------------------------------------------------------------------------------------
  258. pascal void TransformGrid (TObject * tItem, void * tinfo)
  259.     {
  260.     PointInfo    *    info;
  261.     TRow        *    item;
  262.     
  263.     item = (TRow *) tItem;
  264.     info    =    (PointInfo *) tinfo;
  265.     
  266.     item->Each(TransformPoint,info);
  267.     }
  268.     
  269. // --------------------------------------------------------------------------------------------------
  270. //     Draws a boundry section
  271. // --------------------------------------------------------------------------------------------------
  272. pascal void TransformPoint (TObject * tItem, void * tinfo)
  273.     {
  274.     PointInfo    *    info;
  275.     TPoint        *    item;
  276.     
  277.     item = (TPoint *) tItem;
  278.     info = (PointInfo *) tinfo;
  279.     item->TransformPoint(info->magnify);    
  280.     return;
  281.     }
  282.  
  283.